home *** CD-ROM | disk | FTP | other *** search
/ Software of the Month Club 2000 October / Software of the Month - Ultimate Collection Shareware 277.iso / pc / PROGRAMS / UTILITY / WINLINUX / DATA1.CAB / programs_-_include / ASM-SPAR.{_6 / SYSTEM.H < prev    next >
C/C++ Source or Header  |  1999-09-17  |  9KB  |  358 lines

  1. /* $Id: system.h,v 1.72 1999/01/02 16:50:21 davem Exp $ */
  2. #include <linux/config.h>
  3.  
  4. #ifndef __SPARC_SYSTEM_H
  5. #define __SPARC_SYSTEM_H
  6.  
  7. #include <linux/kernel.h>
  8.  
  9. #include <asm/segment.h>
  10.  
  11. #ifdef __KERNEL__
  12. #include <asm/page.h>
  13. #include <asm/oplib.h>
  14. #include <asm/psr.h>
  15. #include <asm/ptrace.h>
  16. #include <asm/btfixup.h>
  17.  
  18. #define EMPTY_PGT       (&empty_bad_page)
  19. #define EMPTY_PGE    (&empty_bad_page_table)
  20. #endif /* __KERNEL__ */
  21.  
  22. #ifndef __ASSEMBLY__
  23.  
  24. /*
  25.  * Sparc (general) CPU types
  26.  */
  27. enum sparc_cpu {
  28.   sun4        = 0x00,
  29.   sun4c       = 0x01,
  30.   sun4m       = 0x02,
  31.   sun4d       = 0x03,
  32.   sun4e       = 0x04,
  33.   sun4u       = 0x05, /* V8 ploos ploos */
  34.   sun_unknown = 0x06,
  35.   ap1000      = 0x07, /* almost a sun4m */
  36. };
  37.  
  38. /* Really, userland should not be looking at any of this... */
  39. #ifdef __KERNEL__
  40.  
  41. extern enum sparc_cpu sparc_cpu_model;
  42.  
  43. #ifndef CONFIG_SUN4
  44. #define ARCH_SUN4C_SUN4 (sparc_cpu_model==sun4c)
  45. #define ARCH_SUN4 0
  46. #else
  47. #define ARCH_SUN4C_SUN4 1
  48. #define ARCH_SUN4 1
  49. #endif
  50.  
  51. extern unsigned long empty_bad_page;
  52. extern unsigned long empty_bad_page_table;
  53. extern unsigned long empty_zero_page;
  54.  
  55. extern struct linux_romvec *romvec;
  56. #define halt() romvec->pv_halt()
  57.  
  58. /* When a context switch happens we must flush all user windows so that
  59.  * the windows of the current process are flushed onto its stack. This
  60.  * way the windows are all clean for the next process and the stack
  61.  * frames are up to date.
  62.  */
  63. extern void flush_user_windows(void);
  64. extern void kill_user_windows(void);
  65. extern void synchronize_user_stack(void);
  66. extern void fpsave(unsigned long *fpregs, unsigned long *fsr,
  67.            void *fpqueue, unsigned long *fpqdepth);
  68.  
  69. #ifdef __SMP__
  70. #define SWITCH_ENTER \
  71.     if(prev->flags & PF_USEDFPU) { \
  72.         put_psr(get_psr() | PSR_EF); \
  73.         fpsave(&prev->tss.float_regs[0], &prev->tss.fsr, \
  74.                &prev->tss.fpqueue[0], &prev->tss.fpqdepth); \
  75.         prev->flags &= ~PF_USEDFPU; \
  76.         prev->tss.kregs->psr &= ~PSR_EF; \
  77.     }
  78.  
  79. #define SWITCH_DO_LAZY_FPU
  80. #else
  81. #define SWITCH_ENTER
  82. #define SWITCH_DO_LAZY_FPU if(last_task_used_math != next) next->tss.kregs->psr&=~PSR_EF;
  83. #endif
  84.  
  85.     /* Much care has gone into this code, do not touch it. */
  86. #define switch_to(prev, next) do {                            \
  87.     __label__ here;                                    \
  88.     register unsigned long task_pc asm("o7");                    \
  89.     extern struct task_struct *current_set[NR_CPUS];                \
  90.     SWITCH_ENTER                                    \
  91.     SWITCH_DO_LAZY_FPU                                \
  92.     __asm__ __volatile__(                                \
  93.     ".globl\tflush_patch_switch\nflush_patch_switch:\n\t"                \
  94.     "save %sp, -0x40, %sp; save %sp, -0x40, %sp; save %sp, -0x40, %sp\n\t"        \
  95.     "save %sp, -0x40, %sp; save %sp, -0x40, %sp; save %sp, -0x40, %sp\n\t"        \
  96.     "save %sp, -0x40, %sp\n\t"                            \
  97.     "restore; restore; restore; restore; restore; restore; restore");        \
  98.     if(!(next->tss.flags & SPARC_FLAG_KTHREAD) &&                    \
  99.        !(next->flags & PF_EXITING))                            \
  100.         switch_to_context(next);                        \
  101.     next->mm->cpu_vm_mask |= (1 << smp_processor_id());                \
  102.     task_pc = ((unsigned long) &&here) - 0x8;                    \
  103.     __asm__ __volatile__(                                \
  104.     "rd    %%psr, %%g4\n\t"                            \
  105.     "std    %%sp, [%%g6 + %3]\n\t"                            \
  106.     "rd    %%wim, %%g5\n\t"                            \
  107.     "wr    %%g4, 0x20, %%psr\n\t"                            \
  108.     "nop\n\t"                                    \
  109.     "std    %%g4, [%%g6 + %2]\n\t"                            \
  110.     "ldd    [%1 + %2], %%g4\n\t"                            \
  111.     "mov    %1, %%g6\n\t"                                \
  112.     ".globl    patchme_store_new_current\n"                        \
  113. "patchme_store_new_current:\n\t"                            \
  114.     "st    %1, [%0]\n\t"                                \
  115.     "wr    %%g4, 0x20, %%psr\n\t"                            \
  116.     "nop\n\t"                                    \
  117.     "nop\n\t"                                    \
  118.     "ldd    [%%g6 + %3], %%sp\n\t"                            \
  119.     "wr    %%g5, 0x0, %%wim\n\t"                            \
  120.     "ldd    [%%sp + 0x00], %%l0\n\t"                        \
  121.     "ldd    [%%sp + 0x38], %%i6\n\t"                        \
  122.     "wr    %%g4, 0x0, %%psr\n\t"                            \
  123.     "nop\n\t"                                    \
  124.     "nop\n\t"                                    \
  125.     "jmpl    %%o7 + 0x8, %%g0\n\t"                            \
  126.     " nop\n\t" : : "r" (&(current_set[hard_smp_processor_id()])), "r" (next),    \
  127.       "i" ((const unsigned long)(&((struct task_struct *)0)->tss.kpsr)),        \
  128.       "i" ((const unsigned long)(&((struct task_struct *)0)->tss.ksp)),        \
  129.       "r" (task_pc)                                    \
  130.     : "g1", "g2", "g3", "g4", "g5", "g7", "l2", "l3",                \
  131.     "l4", "l5", "l6", "l7", "i0", "i1", "i2", "i3", "i4", "i5", "o0", "o1", "o2",    \
  132.     "o3");                                        \
  133. here:  } while(0)
  134.  
  135. /* Changing the IRQ level on the Sparc.   We now avoid writing the psr
  136.  * whenever possible.
  137.  */
  138. extern __inline__ void setipl(unsigned long __orig_psr)
  139. {
  140.     __asm__ __volatile__("
  141.         wr    %0, 0x0, %%psr
  142.         nop; nop; nop
  143. "        : /* no outputs */
  144.         : "r" (__orig_psr)
  145.         : "memory", "cc");
  146. }
  147.  
  148. extern __inline__ void __cli(void)
  149. {
  150.     unsigned long tmp;
  151.  
  152.     __asm__ __volatile__("
  153.         rd    %%psr, %0
  154.         nop; nop; nop;        /* Sun4m + Cypress + SMP bug */
  155.         or    %0, %1, %0
  156.         wr    %0, 0x0, %%psr
  157.         nop; nop; nop
  158. "        : "=r" (tmp)
  159.         : "i" (PSR_PIL)
  160.         : "memory");
  161. }
  162.  
  163. extern __inline__ void __sti(void)
  164. {
  165.     unsigned long tmp;
  166.  
  167.     __asm__ __volatile__("
  168.         rd    %%psr, %0    
  169.         nop; nop; nop;        /* Sun4m + Cypress + SMP bug */
  170.         andn    %0, %1, %0
  171.         wr    %0, 0x0, %%psr
  172.         nop; nop; nop
  173. "        : "=r" (tmp)
  174.         : "i" (PSR_PIL)
  175.         : "memory");
  176. }
  177.  
  178. extern __inline__ unsigned long getipl(void)
  179. {
  180.     unsigned long retval;
  181.  
  182.     __asm__ __volatile__("rd    %%psr, %0" : "=r" (retval));
  183.     return retval;
  184. }
  185.  
  186. extern __inline__ unsigned long swap_pil(unsigned long __new_psr)
  187. {
  188.     unsigned long retval;
  189.  
  190.     __asm__ __volatile__("
  191.         rd    %%psr, %0
  192.         nop; nop; nop;        /* Sun4m + Cypress + SMP bug */
  193.         and    %0, %2, %%g1
  194.         and    %1, %2, %%g2
  195.         xorcc    %%g1, %%g2, %%g0
  196.         be    1f
  197.          nop
  198.         wr    %0, %2, %%psr
  199.         nop; nop; nop;
  200. 1:
  201. "        : "=r" (retval)
  202.         : "r" (__new_psr), "i" (PSR_PIL)
  203.         : "g1", "g2", "memory", "cc");
  204.  
  205.     return retval;
  206. }
  207.  
  208. extern __inline__ unsigned long read_psr_and_cli(void)
  209. {
  210.     unsigned long retval;
  211.  
  212.     __asm__ __volatile__("
  213.         rd    %%psr, %0
  214.         nop; nop; nop;        /* Sun4m + Cypress + SMP bug */
  215.         or    %0, %1, %%g1
  216.         wr    %%g1, 0x0, %%psr
  217.         nop; nop; nop
  218. "        : "=r" (retval)
  219.         : "i" (PSR_PIL)
  220.         : "g1", "memory");
  221.  
  222.     return retval;
  223. }
  224.  
  225. #define __save_flags(flags)    ((flags) = getipl())
  226. #define __save_and_cli(flags)    ((flags) = read_psr_and_cli())
  227. #define __restore_flags(flags)    setipl((flags))
  228.  
  229. #ifdef __SMP__
  230.  
  231. /* This goes away after lockups have been found... */
  232. #ifndef DEBUG_IRQLOCK
  233. #define DEBUG_IRQLOCK
  234. #endif
  235.  
  236. extern unsigned char global_irq_holder;
  237.  
  238. #define save_and_cli(flags)   do { save_flags(flags); cli(); } while(0)
  239.  
  240. #ifdef DEBUG_IRQLOCK
  241. extern void __global_cli(void);
  242. extern void __global_sti(void);
  243. extern unsigned long __global_save_flags(void);
  244. extern void __global_restore_flags(unsigned long flags);
  245. #define cli()            __global_cli()
  246. #define sti()            __global_sti()
  247. #define save_flags(flags)    ((flags)=__global_save_flags())
  248. #define restore_flags(flags)    __global_restore_flags(flags)
  249. #else
  250.  
  251. #error For combined sun4[md] smp, we need to get rid of the rdtbr.
  252.  
  253. /* Visit arch/sparc/lib/irqlock.S for all the fun details... */
  254. #define cli()      __asm__ __volatile__("mov    %%o7, %%g4\n\t"            \
  255.                     "call    ___f_global_cli\n\t"        \
  256.                     " rd    %%tbr, %%g7" : :        \
  257.                     : "g1", "g2", "g3", "g4", "g5", "g7",    \
  258.                       "memory", "cc")
  259.  
  260. #define sti()                            \
  261. do {    register unsigned long bits asm("g7");            \
  262.     bits = 0;                        \
  263.     __asm__ __volatile__("mov    %%o7, %%g4\n\t"        \
  264.                  "call    ___f_global_sti\n\t"    \
  265.                  " rd    %%tbr, %%g2"        \
  266.                  : /* no outputs */            \
  267.                  : "r" (bits)            \
  268.                  : "g1", "g2", "g3", "g4", "g5",    \
  269.                    "memory", "cc");            \
  270. } while(0)
  271.  
  272. #define restore_flags(flags)                        \
  273. do {    register unsigned long bits asm("g7");                \
  274.     bits = flags;                            \
  275.     __asm__ __volatile__("mov    %%o7, %%g4\n\t"            \
  276.                  "call    ___f_global_restore_flags\n\t"    \
  277.                  " andcc    %%g7, 0x1, %%g0"        \
  278.                  : "=&r" (bits)                \
  279.                  : "0" (bits)                \
  280.                  : "g1", "g2", "g3", "g4", "g5",        \
  281.                    "memory", "cc");                \
  282. } while(0)
  283.  
  284. #endif /* DEBUG_IRQLOCK */
  285.  
  286. #else
  287.  
  288. #define cli() __cli()
  289. #define sti() __sti()
  290. #define save_flags(x) __save_flags(x)
  291. #define restore_flags(x) __restore_flags(x)
  292. #define save_and_cli(x) __save_and_cli(x)
  293.  
  294. #endif
  295.  
  296. /* XXX Change this if we ever use a PSO mode kernel. */
  297. #define mb()    __asm__ __volatile__ ("" : : : "memory")
  298. #define rmb()    mb()
  299. #define wmb()    mb()
  300.  
  301. #define nop() __asm__ __volatile__ ("nop");
  302.  
  303. /* This has special calling conventions */
  304. #ifndef __SMP__
  305. BTFIXUPDEF_CALL(void, ___xchg32, void)
  306. #endif
  307.  
  308. extern __inline__ unsigned long xchg_u32(__volatile__ unsigned long *m, unsigned long val)
  309. {
  310. #ifdef __SMP__
  311.     __asm__ __volatile__("swap [%2], %0"
  312.                  : "=&r" (val)
  313.                  : "0" (val), "r" (m));
  314.     return val;
  315. #else
  316.     register unsigned long *ptr asm("g1");
  317.     register unsigned long ret asm("g2");
  318.  
  319.     ptr = (unsigned long *) m;
  320.     ret = val;
  321.  
  322.     /* Note: this is magic and the nop there is
  323.        really needed. */
  324.     __asm__ __volatile__("
  325.     mov    %%o7, %%g4
  326.     call    ___f____xchg32
  327.      nop
  328. "    : "=&r" (ret)
  329.     : "0" (ret), "r" (ptr)
  330.     : "g3", "g4", "g7", "memory", "cc");
  331.  
  332.     return ret;
  333. #endif
  334. }
  335.  
  336. #define xchg(ptr,x) ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
  337. #define tas(ptr) (xchg((ptr),1))
  338.  
  339. extern void __xchg_called_with_bad_pointer(void);
  340.  
  341. static __inline__ unsigned long __xchg(unsigned long x, __volatile__ void * ptr, int size)
  342. {
  343.     switch (size) {
  344.     case 4:
  345.         return xchg_u32(ptr, x);
  346.     };
  347.     __xchg_called_with_bad_pointer();
  348.     return x;
  349. }
  350.  
  351. extern void die_if_kernel(char *str, struct pt_regs *regs) __attribute__ ((noreturn));
  352.  
  353. #endif /* __KERNEL__ */
  354.  
  355. #endif /* __ASSEMBLY__ */
  356.  
  357. #endif /* !(__SPARC_SYSTEM_H) */
  358.